<?php

namespace app\common\model;

use think\Model;

class Cart extends Model
{
    // 表名
    protected $name = 'cart';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
		'status_text',
    ];
	
	
	const STATUS_B = 2;
    const STATUS_Y = 1;
    const STATUS_D = 0;

	public static $statusList = [
		self::STATUS_B => '已购买',
		self::STATUS_Y => '正常',
		self::STATUS_D => '已删除'
	];

	public function user(){
		return $this->belongsTo('user', 'user_id', 'id', '', 'left')->setEagerlyType(0);
	}
	
	public function GetStatusTextAttr($value, $data) {
		$value = isset($value) ? $value : $data['status'];
		$list = self::$statusList;
		return isset($list[$value])?$list[$value]:'';
	}




}
